package com.sx.pipeline.ui.register.adapter

import android.annotation.SuppressLint
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.sx.pipeline.R
import com.sx.pipeline.repos.http.res.AttributeList
import com.sx.pipeline.utils.GlideEngine

/**
 * @Author: YY
 * @Date: 2022/4/23
 * @Description: TODO
 */
class SelectUnitNameAdapter(data: MutableList<AttributeList>)
    : BaseQuickAdapter<AttributeList, BaseViewHolder>(R.layout.item_select_unit_name, data) {

    var clickId: Int = 0

    override fun convert(holder: BaseViewHolder, item: AttributeList) {
        GlideEngine.createGlideEngine()
            .loadImage(context, item.iconUrl,
             holder.getView(R.id.image_unit_name))

        // 单选
        if (clickId == holder.layoutPosition) {
            holder.setImageResource(R.id.image_select, R.drawable.icon_radio_button_checked)
        } else {
            holder.setImageResource(R.id.image_select, R.drawable.icon_radio_button_dischecked)
        }
    }

    @SuppressLint("NotifyDataSetChanged")
    fun setSelectClickId(position: Int) {
        this.clickId = position
        notifyDataSetChanged()
    }
}